<template>
  <el-container>
    <el-header>
      <SearchHeader :key="isRouterAlive" ></SearchHeader>
    </el-header>
    <el-container id="body">
      <el-aside width="200px" style="background-color: rgb(238, 241, 246)">
        <UserAside v-if="pathList.find(item => currentPath.includes(item))"></UserAside>
        <HomeAside v-else></HomeAside>
      </el-aside>
      <el-main style="padding: 0 20px; height: calc(100vh - 60px);">
        <router-view v-if="isRouterAlive"/>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import SearchHeader from "@/components/container/SearchHeader";
import HomeAside from "@/components/container/HomeAside";
import UserAside from "@/components/container/UserAside";
import {ref, nextTick, provide} from "vue";

export default {
  data() {
    return {
      pathList: ['/user', '/merchant/', '/account', '/book/', 'payFarmCrops'],
      currentPath: "",
    }
  },
  components: {
    SearchHeader,
    HomeAside,
    UserAside,
  },
  watch: {
    $route: {
      handler: function(to){
        this.currentPath = to.fullPath;
        // console.log(to.fullPath.includes("user"));
      },
      // 深度观察监听
      deep: true
    },
  },
  setup() {
    // 局部组件刷新
    const isRouterAlive = ref(true);
    const reload = () => {
      isRouterAlive.value = false;
      nextTick(() => {
        isRouterAlive.value = true;
      });
    };
    provide("reload", reload);
    return {
      isRouterAlive,
    };
  },
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  min-width: 1280px;
  margin: 0;
}

#body {
  min-width: 1280px;
  max-width: 1680px;
  margin: auto;
}
.el-container {
  height: 100vh;
}
.el-main {
  width: 1000px;
}
.el-header{
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(to bottom right, #a0cfff, #8cc5ff, #79bbff, #66b1ff, #53a8ff);
}
.grid-content {
  border-radius: 4px;
  min-height: 36px;
}
.user-bar {
  border-radius: 4px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: right;
  padding: 0 18px;
}
</style>
